package com.originskyseed.platform.count.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.util.bean.PrimaryKeyGeneratorUtil;
import com.originskyseed.platform.count.mapper.FeeCategoryMapper;
import com.originskyseed.platform.count.model.FeeCategory;
import com.originskyseed.platform.count.service.IFeeCategoryService;

/**
 * 费用类别表Service接口实现类（OSI_FEE_CATEGORY）
 * 
 * @author Tangwanghui
 */
@DubboService
@Component("feeCategoryService")
public class FeeCategoryServiceImpl implements IFeeCategoryService {

	@Resource
	private FeeCategoryMapper feeCategoryMapper;

	/**
	 * 删除记录
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKey(String id) throws Exception {
		return this.feeCategoryMapper.deleteByPrimaryKey(id);
	}

	/**
	 * 批量删除记录
	 * 
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKeys(List<String> ids) throws Exception {
		return this.feeCategoryMapper.deleteByPrimaryKeys(ids);
	}


	/**
	 * 批量删除记录
	 *
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	public int updateByIds(List<String> ids,Integer isDel) throws Exception
	{
		return this.feeCategoryMapper.updateByIds(isDel,ids);
	}

	/**
	 * 插入记录
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insert(FeeCategory record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.feeCategoryMapper.insert(record);
	}

	/**
	 * 插入记录（仅非空值字段）
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insertSelective(FeeCategory record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.feeCategoryMapper.insertSelective(record);
	}

	/**
	 * 更新记录
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKey(FeeCategory record) throws Exception {
		record.setUpdateTime(new Date());
		return this.feeCategoryMapper.updateByPrimaryKey(record);
	}

	/**
	 * 更新记录（仅非空值字段）
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKeySelective(FeeCategory record) throws Exception {
		record.setUpdateTime(new Date());
		return this.feeCategoryMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * 查询记录
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public FeeCategory selectByPrimaryKey(String id) throws Exception {
		return this.feeCategoryMapper.selectByPrimaryKey(id);
	}

	/**
	 * 查询列表
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<FeeCategory> selectList(FeeCategory record) throws Exception {
		return this.feeCategoryMapper.selectList(record);
	}

	/**
	 * 分页查询列表
	 * 
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<FeeCategory> selectListByPage(Map<String, Object> params, BasePage<FeeCategory> page) throws Exception {
		params.put("page", page);
		List<FeeCategory> list = this.feeCategoryMapper.selectListByPage(params);
		page.setResults(list);
		return page;
	}

}